package com.addict.applocker.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;

/**
 * 自定义的浮动按钮，加了v4、v7包了，不想再加Desgin包了，
 * 要不软件体积那一个大...
 */
public class FloatButton extends ImageButton{
    public FloatButton(Context context) {
        super(context); init();
    }
    public FloatButton(Context context, AttributeSet attrs) {
        super(context, attrs); init();
    }
    public FloatButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr); init();
    }

    private void init() { }

    // 资源
    private int mColor = 0;
    private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    public void setBackgroundColor(int color) {
        this.mColor = color;
        mPaint.setColor(color);
    }



    @Override
    protected void onDraw(Canvas canvas) {
        if(mPaint == null) { super.onDraw(canvas);  return; }

        int roundWidth = (getWidth() > getHeight() ? getHeight() : getWidth()) / 2;
        canvas.drawCircle(getWidth() / 2, getHeight() / 2, roundWidth, mPaint);
        super.onDraw(canvas);
    }
}
